const mongoose = require('mongoose');
// 连接到MongoDB数据库
// MongoDB连接字符串
const mongoDB = 'mongodb://127.0.0.1:27017/mydb';
mongoose.connect(mongoDB,{ useNewUrlParser: true, useUnifiedTopology: true })

const db = mongoose.connection;

db.once('open', function() {
    console.log("成功连接到数据库");
});
// 绑定连接错误事件监听
db.on('error', err => {
    console.error('MongoDB 连接错误：', err);
});

module.exports = db;
